package com.ruoyi.web.controller.cashier;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.MemberChangeRecords;
import com.ruoyi.system.service.IMemberChangeRecordsService;
import com.ruoyi.system.util.AbdulEmptyUtils;
import com.ruoyi.system.util.BaseResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/changeRecord")
@Api(tags = "会员资金变动记录管理")
public class MemberChangeRecordsController extends BaseController {

    @Autowired
    private IMemberChangeRecordsService changeRecordsService;

    @PostMapping("/page")
    @ApiOperation("获取所有资金变动记录")
    public BaseResponse<IPage<MemberChangeRecords>> list(@RequestBody MemberChangeRecords memberChangeRecords) {
        LambdaQueryWrapper<MemberChangeRecords> wrapper = Wrappers.lambdaQuery();
        wrapper.eq(!AbdulEmptyUtils.isEmpty(memberChangeRecords.getMemberId()), MemberChangeRecords::getMemberId, memberChangeRecords.getMemberId());
        wrapper.eq(!AbdulEmptyUtils.isEmpty(memberChangeRecords.getCardNumber()), MemberChangeRecords::getCardNumber, memberChangeRecords.getCardNumber());
        wrapper.eq(!AbdulEmptyUtils.isEmpty(memberChangeRecords.getChangeType()), MemberChangeRecords::getChangeType, memberChangeRecords.getChangeType());
        wrapper.orderByDesc(MemberChangeRecords::getCreateTime);
        IPage<MemberChangeRecords> page = new Page<>(memberChangeRecords.getPageNum(), memberChangeRecords.getPageSize());
        IPage<MemberChangeRecords> recordsIPage = changeRecordsService.page(page, wrapper);
        return BaseResponse.success(recordsIPage);
    }
}
